
<template>
  <div class="auth-loading" style="text-align:center;padding-top:100px">登录中...</div>
</template>
<script>
import router from '@/router'
import { gotoAuthLogin } from '@/utils/auth'
export default {
  async created() {
    const { query } = this.$route
    const redirectUrl = query.redirect_url
    const ticket = query.ticket
    if (!ticket) {
      gotoAuthLogin(redirectUrl)
    } else {
      try {
        // const { roles } = await this.$store.dispatch('user/getInfo', { ticket: ticket, appId: process.env.VUE_APP_APPID })
        const { roles } = await this.$store.dispatch('user/getInfo', { ticket: ticket, appId: process.env.VUE_APP_APPID })
        const accessRoutes = await this.$store.dispatch('permission/generateRoutes', roles)
        router.addRoutes(accessRoutes)
        // 去跳转
        console.log('redirectUrl:', redirectUrl)
        location.replace(redirectUrl)
      } catch (error) {
        // remove token and go to login page to re-login
        await this.$store.dispatch('user/resetToken')
        // Message.error(error || 'Has Error')
        gotoAuthLogin(redirectUrl)
      }
    }
  },
  methods: {

  }
}
</script>
